package panel.viewSpots.navigation
{
	import assists.HtmlText;
	import assists.TextFieldUtils;
	import assists.resource.ResourceLoader;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	
	import panel.viewSpots.StaticSlide;
	
	public class ViewSpotChoose extends Sprite
	{
		private var _loader:ResourceLoader;
		private var _stage:Stage;

		private var _introTxt:TextField;
		private var _btnContainer:Sprite;
		private var _btnItemList:Array;
		private var _startSeek:Function;
		public function ViewSpotChoose(loader:ResourceLoader,stage:Stage)
		{
			_loader = loader;
			_stage = stage;
			init();
		}
		
		private function init():void
		{
			_introTxt = new TextField();
			_introTxt.mouseEnabled = false;
			_introTxt.width = _stage.stageWidth;
			_introTxt.autoSize = "center";
			TextFieldUtils.setHtmlText(_introTxt,HtmlText.formatSizeColor("请选择您当前所在景区",0xffffff,26));
			
			_btnContainer = new Sprite();
			_btnContainer.y = _introTxt.y + _introTxt.height;
			this.addChild(_btnContainer);
			this.addChild(_introTxt);
			
			this.graphics.beginFill(0);
			this.graphics.drawRect(0,0,_stage.stageWidth,_introTxt.height);
			this.graphics.endFill();
		}
		
		public function show(dataList:Array,startSeekFunc:Function):void
		{
			_btnItemList = [];
			_startSeek = startSeekFunc;
			var info:Object;
			for(var i:int=0;i<dataList.length;i++)
			{
				info = dataList[i];
				var button:BtnClouree = new BtnClouree();
				button.data = info;
				button.width = _stage.stageWidth;
				button.height = _stage.stageWidth * 0.2;
				button.label(info.name,24);
				button.y = i * button.height;
				_btnContainer.addChild(button);
				button.addEventListener(MouseEvent.MOUSE_UP,clickBtnHandler);
				_btnItemList.push(button);
			}
			StaticSlide.beginSlide(_btnContainer,_stage,new Rectangle(0,_btnContainer.y,0,-_btnContainer.height));
		}
		
		protected function clickBtnHandler(event:MouseEvent):void
		{
			var btn:BtnClouree = event.currentTarget as BtnClouree;
			_startSeek(btn.data.id);
		}
		
		public function clear():void
		{
			StaticSlide.clear(_btnContainer);
			var btn:BtnClouree;
			for(var i:int=0;i<_btnItemList.length;i++)
			{
			  btn = _btnItemList[i];	
			  btn.removeEventListener(MouseEvent.CLICK,clickBtnHandler);
			  _btnContainer.removeChild(btn);
			}
			if(this.parent)
			{
				this.parent.removeChild(this);
			}
		}
		
	}
}